<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<script type="text/html" id="printTabTool">
    <div class="layui-btn-container" style="padding:20px 10px;">

        <button class="layui-btn layui-btn-sm" id="add" lay-event="add">
            <i class="layui-icon layui-icon-add-1"></i>
            <span>添加</span>
        </button>
    </div>
    <form class="layui-form" action="" style="margin-top:10px" lay-filter="printForm">
        <div class="table-top-filter" style="position: relative">
            <div class="table-filter-alone">
                <label class="layui-form-label">模板名称</label>
                <input type="text" id="templateName" name="Q_templateName_SL" lay-verify="required" class="layui-input filter-value"
                       autocomplete="off"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">别名</label>
                <input type="text" id="printAlias" lay-verify="required" autocomplete="off" name="Q_alias_SL"
                       class="layui-input filter-value">
            </div>
        </div>
        <a class="layui-btn layui-btn-sm" id="query" lay-event="query" style="position: absolute;top: 84px;right: 286px;">
            <i class="layui-icon layui-icon-search"></i>
            <span>查询</span>
        </a>
    </form>
</script>
<div style="width: 100%; ">
    <table class="layui-hide" id="templateTab" lay-filter="templateTab"></table>
</div>
<div class="layui-form-item">
    <div class="layui-input-block" style="margin:0;position: absolute;bottom:10px;left:46%">
        <div class="layui-footer">
            <button type="button" class="layui-btn layui-btn-danger" id="returns">关闭</button>
        </div>
    </div>
</div>
<div class="addSer" hidden>
</div>
<script type="text/html" id="operation">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="preview">预览</a>
    {{# if(d.isDefault != 1){ }}
    <a class="layui-btn layui-btn-xs" lay-event="default">设置默认</a>
    {{# }}}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    var formKey = '${formKey}';
    layui.config({
        base: serverPath.formPath + staticPath.formPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'form', 'layedit', 'laydate', 'jquery', 'table', 'layer', 'setter','totalFilter','common'], function () {
        var form = layui.form,totalFilter=layui.totalFilter,common=layui.common;
        var layer = layui.layer;
        var table = layui.table;
        var $ = layui.$;
        var setter = layui.setter;
        var index = parent.layer.getFrameIndex(window.name);
        $("#returns").on('click', function () {
            parent.layer.close(index);
        });
        table.render({
            elem: '#templateTab'
            , url: serverPath.formPath + setter.formLinkPath + "printTemplate/list"
            , toolbar: '#printTabTool'
            , height: 500
            , defaultToolbar: []
            , cols: [[
                {field: 'templateName', title: '模板名称', align: "center"}
                , {field: 'alias', title: '别名', align: "center", minWidth: 80}
                , {
                    field: 'isDefault', title: '是否默认', align: "center", minWidth: 80,
                    templet: function (d) {
                        if (d.isDefault == 1) {
                            return '<span style="color:green;">' + '是' + '</span>';
                        }
                        return '<span style="color:red;">' + '否' + '</span>';
                    }
                }
                , {
                    field: 'isPrintInFinish', title: '是否在流程结束后显示', align: "center", minWidth: 180,
                    templet: function (d) {
                        if (d.isPrintInFinish == 1) {
                            return '<span style="color:green;">' + '是' + '</span>';
                        }
                        return '<span style="color:red;">' + '否' + '</span>';
                    }
                }
                , {
                    field: 'isPrintInFinish', title: '是否显示普通表单', align: "center", minWidth: 150,
                    templet: function (d) {
                        if (d.isPrintInForm == 1) {
                            return '<span style="color:green;">' + '是' + '</span>';
                        }
                        return '<span style="color:red;">' + '否' + '</span>';
                    }
                }
                , {fixed: 'right', title: '管理', toolbar: '#operation', width: 180, align: 'center'}
            ]]
            , where: {
                formKey: formKey
            }
            , page: true
        });
        totalFilter.init('templateTab');
        table.on('radio', function (data) {
            var mainTableId = data['data']['tableId'];
            var mainTableName = data['data']['tableName'];
            parent.$('#mainTableId').val(mainTableId);
            parent.$('#mainTableName').val(mainTableName);
        });

        $("#chiose").on('click', function (data) {
            parent.layer.close(index);
        });
        //头工具栏事件
        table.on('toolbar(templateTab)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data; //获取选中行数据
            switch (obj.event) {
                case 'query':
                    common.tableConditionRender("templateTab","printForm",{where:{}},false);
                    break;
                case 'add':
                    window.open(serverPath.formPath + setter.formLinkPath + 'printTemplate/view/formDesign/printFormDevise?formKey=' + formKey);
                    break;
            }
        });
        //监听行工具事件
        table.on('tool(templateTab)', function (obj) {
            var data = obj.data;
            var printId = data.id;
            switch (obj.event) {
                case 'edit':
                    window.open(serverPath.formPath + setter.formLinkPath + 'printTemplate/view/formDesign/printFormDevise?id=' + printId + '&formKey=' + formKey);
                    break;
                case 'preview':
                    window.open(serverPath.formPath + setter.formLinkPath + 'printTemplate/view/formDesign/printFormPreview?printTemplateId=' + printId);
                    break;
                //设置默认
                case 'default':
                    $.ajax({
                        url: serverPath.formPath + setter.formLinkPath + "printTemplate/setDefault",
                        dataType: 'json',
                        method: 'post',
                        data: {"formKey": formKey, "id": printId},
                        success: function (data) {
                            layer.alert(data.msg);
                            //执行重载
                            table.reload('templateTab', {
                                page: {
                                    curr: 1
                                }
                            });
                        }
                    });
                    break;
                case 'del':
                    layer.confirm('确定要删除该模板吗?', function (index) {
                        $.ajax({
                            url: serverPath.formPath + setter.formLinkPath + "printTemplate/del",
                            dataType: 'json',
                            data: {"id": printId},
                            success: function (data) {
                                layer.alert(data.msg);
                                //执行重载
                                table.reload('templateTab', {
                                    page: {
                                        curr: 1
                                    }
                                });
                            }
                        });
                        return false;
                    });
                    break;
            }
        });
    });
</script>
</body>
</html>